package com.visikard.item;

import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class ItemRedeemDetails implements Parcelable {
	
	String paymentMethod;
	String redeemptionCode;
	String kardNumber;
	long dateTime;
	String redemptionValue;
	long redeemedTransactionId;
	String dateTimeWithTimezone;
	String address;
	
	public ItemRedeemDetails(){}
	
	public ItemRedeemDetails(JSONObject job){
		if(job == null)
    		return;
		paymentMethod = job.optString("paymentMethod", "");
		if(paymentMethod == null || paymentMethod.equals("null"))
			paymentMethod = "";
		
		redeemptionCode = job.optString("redeemptionCode", "");
		if(redeemptionCode == null || redeemptionCode.equals("null"))
			redeemptionCode = "";
		
		kardNumber = job.optString("kardNumber", "");
		if(kardNumber == null || kardNumber.equals("null"))
			kardNumber = "";
		
		dateTime = job.optLong("dateTime", 0);
		
		redemptionValue = job.optString("redemptionValue", "0.00");
		if(redemptionValue == null || redemptionValue.equals("null"))
			redemptionValue = "0.00";
		
		redeemedTransactionId = job.optLong("redeemedTransactionId", -1);
		
		dateTimeWithTimezone = job.optString("dateTimeWithTimezone", "");
		if(dateTimeWithTimezone == null || dateTimeWithTimezone.equals("null"))
			dateTimeWithTimezone = "";
		
		address = job.optString("address", "");
		if(address == null || address.equals("null"))
			address = "";
	}
	
	public String getPaymentMethod() {
		return paymentMethod;
	}

	public String getRedeemptionCode() {
		return redeemptionCode;
	}

	public String getKardNumber() {
		return kardNumber;
	}

	public long getDateTime() {
		return dateTime;
	}

	public String getRedemptionValue() {
		return redemptionValue;
	}

	public long getRedeemedTransactionId() {
		return redeemedTransactionId;
	}

	public String getDateTimeWithTimezone() {
		return dateTimeWithTimezone;
	}

	public String getAddress() {
		return address;
	}

	protected ItemRedeemDetails(Parcel src){
		paymentMethod = src.readString();
		redeemptionCode = src.readString();
		kardNumber = src.readString();
		dateTime = src.readLong();
		redemptionValue = src.readString();
		redeemedTransactionId = src.readLong();
		dateTimeWithTimezone = src.readString();
		address = src.readString();
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel target, int flags) {
		
		target.writeString(paymentMethod);
		target.writeString(redeemptionCode);
		target.writeString(kardNumber);
		target.writeLong(dateTime);
		target.writeString(redemptionValue);
		target.writeLong(redeemedTransactionId);
		target.writeString(dateTimeWithTimezone);
		target.writeString(address);
	}
	
	public static final Parcelable.Creator<ItemRedeemDetails> CREATOR = new Creator<ItemRedeemDetails>() {
		@Override
		public ItemRedeemDetails createFromParcel(Parcel source) {
			return new ItemRedeemDetails(source);
		}

		@Override
		public ItemRedeemDetails[] newArray(int size) {
			return new ItemRedeemDetails[size];
		}
	};

}
